<?php
/**
 * 上传多个文件代码
 */


/* Form */
echo '<b>-------- UPLOADING --------</b>';
echo "\r\n" . '<form action="" method="POST" enctype="multipart/form-data">';
for ($i = 0; $i < 10; $i ++) {
    echo "\r\n" . '<p>' . $i . ') <input type="file" name="file[' . $i . ']" /></p>';
}
echo "\r\n" . '<p><input type="submit" value="Click to upload file(s)" /></p>' . "\r\n" . '</form>';
/* Upload */
if ($_FILES and $_FILES['file']) {
    $strSavePath = str_replace('\\', '/', dirname('__FILE__')) . '/uploaded_files';
    !file_exists($strSavePath) && mkdir($strSavePath, 0777);
    $intNow = time();
    $j = 0;
    for ($i = 0; $i < 10; $i ++) {
        $bln = isset($_FILES['file']['name']);
        $bln && $bln = is_array($_FILES['file']['name']);
        $bln && $bln = isset($_FILES['file']['name'][$i]);
        $bln && $bln = !empty($_FILES['file']['name'][$i]);
        $bln && $strSavedFileName = $strSavePath . '/' . $intNow . '_' . $i . '_' . $_FILES['file']['name'][$i];
        $bln && $bln = move_uploaded_file($_FILES['file']['tmp_name'][$i], $strSavedFileName);
        $bln && $j ++;
    }
    echo 'Uploaded ' . $j . ' file(s).';
}